﻿using System;

namespace Bilibili.Model.Resource
{
    public sealed class DashItem
    {
        private string baseUrl;
        public string BaseUrl
        {
            get
            {
                if (string.IsNullOrEmpty(baseUrl))
                    return Base_Url;
                return baseUrl;
            }
            set => baseUrl = value;
        }
        public string Base_Url { get; set; }
        public string Bandwidth { get; set; }
        public string Codecs { get; set; }
        public int Codecid { get; set; }
        private string frameRate;
        public string FrameRate
        {
            get
            {
                if (string.IsNullOrEmpty(frameRate))
                    return Frame_Rate;
                return frameRate;
            }
            set => frameRate = value;
        }
        public string Frame_Rate { get; set; }
        public string Height { get; set; }
        public string Width { get; set; }
        public int Id { get; set; }
        public string Sar { get; set; }
        private string mimeType;
        public string MimeType
        {
            get
            {
                if (string.IsNullOrEmpty(mimeType))
                    return Mime_Type;
                return mimeType;
            }
            set => mimeType = value;
        }
        public string Mime_Type { get; set; }
        public int StartWithSap { get; set; }
        private SegmentBase segmentBase;
        public SegmentBase SegmentBase
        {
            get
            {
                if (null == segmentBase)
                    return Segment_Base;
                return segmentBase;
            }
            set => segmentBase = value;
        }
        public SegmentBase Segment_Base { get; set; }
        public string Fps
        {
            get
            {
                try
                {
                    if (!string.IsNullOrEmpty(FrameRate))
                    {
                        var values = FrameRate.Split('/');
                        if (values.Length == 1)
                            return FrameRate;
                        return (Convert.ToDouble(values[0]) / Convert.ToDouble(values[1])).ToString("0.0");
                    }
                    else if (!string.IsNullOrEmpty(Frame_Rate))
                    {
                        var values = Frame_Rate.Split('/');
                        if (values.Length == 1)
                            return Frame_Rate;
                        return (Convert.ToDouble(values[0]) / Convert.ToDouble(values[1])).ToString("0.0");
                    }
                }
                catch { }
                return "0";
            }
        }
    }
}